﻿using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;

namespace Findy.XsltDb
{
    public partial class DesktopModules_XsltDb_ViewXsltDb : XsltDbPortalModuleBase, IActionable
    {
        string resourcePath = "~/DesktopModules/XsltDb/App_LocalResources/ViewXsltDb.ascx";

        public ModuleActionCollection ModuleActions
        {
            get
            {

                ModuleActionCollection Actions = new ModuleActionCollection();

                if (UserInfo.IsInRole("Administrators"))
                {
                    if ((new ModuleController().GetModuleSettings(ModuleId)["XsltDb.EditorEnabled"] ?? String.Empty).ToString() != "False")
                    {
                        string returnurl = HttpUtility.UrlEncodeUnicode(Regex.Replace(Request.RawUrl,
                            @"(\?|&)__U=\d+", string.Empty));
                        Actions.Add(
                            this.GetNextActionID(),
                            XsltDbResX.Localize("EditXSLT.Text", resourcePath),
                            ModuleActionType.AddContent,
                            "",
                            "",
                            this.EditUrl("returnurl", returnurl),
                            false,
                            SecurityAccessLevel.Admin,
                            true,
                            false);

                        if (UserInfo.IsSuperUser)
                        {
                            Actions.Add(
                                this.GetNextActionID(),
                                XsltDbResX.Localize("Package.Text", resourcePath),
                                ModuleActionType.ExportModule,
                                "",
                                "",
                                this.EditUrl("returnurl", returnurl, "Package"),
                                false,
                                SecurityAccessLevel.Admin,
                                true,
                                false);
                        }
                    }
                }

                return Actions;
            }
        }
    }
}